<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/12/30
  Time: 11:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>欢迎二次元用户</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="<%=request.getContextPath()%>/static/js/jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/bootstrap.css" />
    <script src="<%=request.getContextPath()%>/static/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <link href="<%=request.getContextPath()%>/template/css/base.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/template/css/index.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/button.css" />
    <script type="text/javascript">
        var system ={};
        var p = navigator.platform;
        system.win = p.indexOf("Win") == 0;
        system.mac = p.indexOf("Mac") == 0;
        system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
        if(system.win||system.mac||system.xll){//如果是电脑跳转到
            window.location.href="#";
        }else{  //如果是手机,跳转到
            window.location.href="${pageContext.request.contextPath}/index.jsp";
        }
    </script>

</head>
<body>
<header>
    <!-- 头像 -->
    <div class="top-section col-md-6" id="headPicture">
        <div class="profile-image col-md-6">
            <a href="${pageContext.request.contextPath}/user/userDetails">
                <img src="${user.picture}" class="img-circle center-block" width="80px" height="80px">
            </a>
        </div>
        <div class="profile-content col-md-6">
            <h3 class="profile-title text-center">${user.userName}</h3>
            <h5 class="profile-description text-center">${user.signature}</h5>
        </div>
    </div>

    <button class="btn btn-danger col-md-1.5" id="logout" style="margin-top: 23px">
        <span class="glyphicon glyphicon-off"></span>退出登录
    </button>

    <nav class="nav col-md-4 topnav" id="topnav">
        <a href="${pageContext.request.contextPath}/anime/animeUser"><span>首页</span><span class="en">index</span></a>
        <a href="${pageContext.request.contextPath}/user/userDetails"><span>编辑个人资料</span><span class="en">editor</span></a>
    </nav>
</header>

<article>
    <h2 class="title_tj">
        <p><span></span></p>
    </h2>
    <div class="bloglist center" id="allList">
        <div>
            <div class="panel panel-default">
                <div class="page-header">
                    <!-- 头像 -->
                    <div class="top-section">
                        <div class="profile-image">
                            <img src="${user.picture}" class="img-circle center-block" width="150px" height="150px">
                        </div>
                        <div class="profile-content">
                            <button class="btn btn-default center-block" data-toggle="modal" data-target="#exampleModal2" data-whatever="上传动漫封面" id="upload"><span class="glyphicon glyphicon-edit" ></span>上传头像</button>
                        </div>
                    </div>

                </div>

                <div class="panel-body">
                    <div class="col-md-4">

                    </div>

                    <div class="col-md-8">
                        <table class="center-block">
                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">用户Id：</span></h4></td>
                                <td><h4><span class="text-left">${user.userId}</span></h4></td>
                            </tr>

                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">用户名：</span></h4></td>
                                <td><h4><span class="text-left">${user.userName}</span></h4></td>
                            </tr>

                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">手机号：</span></h4></td>
                                <td><h4><span class="text-left">${user.phone}</span></h4></td>
                            </tr>

                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">年龄：</span></h4></td>
                                <td><h4><span class="text-left">${user.age}</span></h4></td>
                            </tr>

                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">性别：</span></h4></td>
                                <td><h4><span class="text-left">${user.sex}</span></h4></td>
                            </tr>

                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">个性签名：</span></h4></td>
                                <td><h4><span class="text-left">${user.signature}</span></h4></td>
                            </tr>

                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">创号时间：</span></h4></td>
                                <td><h4><span class="text-left">${user.createTime}</span></h4></td>
                            </tr>

                            <tr style="line-height: 15px">
                                <td><h4><span class="text-right">最后登录时间：</span></h4></td>
                                <td><h4><span class="text-left">${user.lastLoginTime}</span></h4></td>
                            </tr>


                            <tr>
                                <td colspan="2"> <button class="btn btn-danger" data-toggle="modal" data-target="#exampleModal" data-whatever="修改管理员信息" id="update"><span class="glyphicon glyphicon-edit" ></span>点击修改</button></td>
                            </tr>
                        </table>
                    </div>

                </div>
            </div>

        </div>

    </div>


    <script type="text/javascript" id="bdshare_js" data="type=tools&amp;uid=6574585" ></script>
    <script type="text/javascript" id="bdshell_js"></script>
</article>

<footer>
    <img src="<%=request.getContextPath()%>/static/img/1026.jpg" width="100%" height="200px">
</footer>

<!--增加、修改、查看详情弹框-->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">New message</h4>
            </div>

            <div class="modal-body">
                <div class="center-block">
                    <form class="form-horizontal" id="Form" enctype="multipart/form-data">

                        <!-- adminId  -->
                        <div class="form-group">
                            <label for="userId" class="col-sm-3 control-label">用户Id：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control userId" id="userId" placeholder="管理员Id" name="userId" required="required" disabled="disabled"/>
                            </div>
                        </div>

                        <!-- adminName  -->
                        <div class="form-group">
                            <label for="userName" class="col-sm-3 control-label">用户名：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control userName" id="userName" placeholder="姓名" name="userName" required="required"/>
                            </div>
                        </div>

                        <!--  adminPassword -->
                        <div class="form-group">
                            <label for="userPassword" class="col-sm-3 control-label">密码:</label>
                            <div class="col-sm-9">
                                <input type="password" class="form-control userPassword" id="userPassword" placeholder="密码" name="userPassword" required="required"/>
                            </div>
                        </div>


                        <!-- phone  -->
                        <div class="form-group">
                            <label for="phone" class="col-sm-3 control-label">手机号：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control phone" id="phone" placeholder="手机号" name="phone" required="required"/>
                            </div>
                        </div>

                        <!-- age  -->
                        <div class="form-group">
                            <label for="age" class="col-sm-3 control-label">年龄：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control age" id="age" placeholder="年龄" name="age" required="required"/>
                            </div>
                        </div>

                        <!-- sex  -->
                        <div class="form-group">
                            <label for="sex" class="col-sm-3 control-label">性别：</label>
                            <div class="col-sm-9">
                                <select class="form-control sex" id="sex" name="sex">
                                    <option value="-1">请选择性别</option>
                                    <option value="0">男</option>
                                    <option value="1">女</option>
                                </select>
                            </div>
                        </div>

                        <!-- signature  -->
                        <div class="form-group">
                            <label for="signature" class="col-sm-3 control-label">个性签名：</label>
                            <div class="col-sm-9">
                                <textarea class="form-control signature" id="signature" rows="3" name="signature"></textarea>
                            </div>
                        </div>

                    </form>
                </div>

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary save" id="save">确定</button>
                <button type="button" class="btn btn-primary update " style="display: none;">修改</button>
            </div>
        </div>
    </div>
</div>

<!--上传图片弹框-->
<div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel2">上传头像</h4>
            </div>

            <div class="modal-body">
                <form class="form-horizontal" id="uploadForm" enctype="multipart/form-data">

                    <div class="form-group divHide">
                        <label for="uploadFile" class="col-sm-3 control-label">用户头像：</label>
                        <div class="col-sm-5">
                            <input type="file" class="form-control" placeholder="" name="uploadFile" id="uploadFile" multiple="multiple">
                        </div>
                    </div>

                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary upload" >上传</button>
            </div>
        </div>
    </div>
</div>
</body>

<script type="text/javascript">
    $(function () {
        //弹窗部分
        $('#exampleModal').on('show.bs.modal', function(event) {
            var button = $(event.relatedTarget);
            var recipient = button.data('whatever');

            var modal = $(this);
            modal.find('.modal-title').text(recipient);
//				modal.find('.modal-body input').val(recipient);
        })

        /*数据回显*/
        $(document).on("click", "#update", function() {

            var userId = ${user.userId};
            console.log(userId);

            $(".divHide").show();
            $(".update").show();
            $("#save").hide();

            $.post("${pageContext.request.contextPath}/user/userBy", {
                userId: userId
            }, function(data) {
                console.log(data);
                //将后台返回的数据给对应的表单元素赋值
                $(".userId").val(data.data.userId);
                $(".userName").val(data.data.userName);
                $(".userPassword").val(data.data.userPassword);
                $(".phone").val(data.data.phone);
                $(".sex").val(data.data.sex);
                $(".age").val(data.data.age);
                $(".signature").val(data.data.signature);
                $(".createTime").val(data.data.createTime);
                $(".lastLoginTimeTime").val(data.data.lastLoginTime);
            }, "json")
        });

        /*修改操作*/
        $(document).on("click", ".update", function() {
            var userId = ${user.userId};
            console.log(userId);

            console.log($("#Form").serialize());

            $.ajax({
                type: "POST",
                data: $("#Form").serialize(),
                url: "${pageContext.request.contextPath}/user/updateUser?userId="+userId,
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    if(data.code == 200) {
                        alert(data.msg);
                        $("#myModalLabel").modal("hide");
                        window.location.reload();
                    } else {
                        alert(data.msg);
                    }

                }
            })

        })

        /*上传操作*/
        $(document).on("click", "#upload", function() {

            var userId = ${user.userId};
            console.log(userId);


            $(document).on("click", ".upload", function() {

                var formData = new FormData($("#uploadForm")[0]);
                console.log(formData);

                $.ajax({
                    type: "POST",
                    data: formData,
                    url: "${pageContext.request.contextPath}/user/uploadPicture?userId="+userId,
                    dataType: "json",
                    processData:false,
                    contentType:false,
                    success: function(data) {
                        console.log(data);
                        if(data.code == 200) {
                            alert(data.msg);
                            $("#myModalLabel").modal("hide");
                            window.location.reload();
                        } else {
                            alert(data.msg);
                        }
                    }
                })
            })

        })

        //退出登录
        $(document).on("click", "#logout", function() {
            if(confirm('是否要退出登录？')) {
                $.get(
                    "${pageContext.request.contextPath}/user/logout",
                    function(data) {
                        window.location.reload();
                    }, "json")
            }
        })
    })


</script>
</html>
